﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;

namespace AvansRS.Domain
{
    public class Person
    {        
        public virtual int ID { get; set; }

        [Required(ErrorMessage="Voornaam is verplicht.")]
        public virtual string FirstName { get; set; }
        [Required(ErrorMessage = "Achternaam is verplicht.")]
        public virtual string SurName { get; set; }
        
        [Required(ErrorMessage = "Nummer is verplicht.")]
		  [RegularExpression("[0-9]{2,10}", ErrorMessage = "Nummer niet geldig.")]
        public virtual int Number { get; set; }

        public virtual Account Account { get; set; }
        //public virtual IList<EventDate> Appointments { get; private set; }
        [Required]
        public virtual Entity Entity { get; set; }

        public virtual Academy Academy { get; set; }
        public virtual Study Study { get; set; }

        public virtual string sName
        {
            get
            {
                return FirstName + " " + SurName;
            }
        }

        private Docent _docentDetails;
        private Student _studentDetails;

        public virtual Docent DocentDetails {
            get
            {
                return _docentDetails;
            }
            set
            {
                if (_studentDetails != null && value != null)
                    throw new ArgumentException("Person cannot have both DocentDetails and StudentDetails");
                _docentDetails = value;
            }
        }

        public virtual Student StudentDetails {
            get
            {
                return _studentDetails;
            }
            set
            {
                if (_docentDetails != null && value != null)
                    throw new ArgumentException("Person cannot have both StudentDetails and DocentDetails");
                _studentDetails = value;
            }
        }

        public virtual PersonType Type
        {
            get
            {
                if (_docentDetails != null && _studentDetails == null)
                    return PersonType.Docent;
                if (_studentDetails != null && _docentDetails == null)
                    return PersonType.Student;

                return PersonType.None;
            }
        }
    }
}
